package com.example.java_blog.model;

import com.example.java_blog.constants.Constant;
import lombok.Data;

import javax.swing.plaf.PanelUI;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 均先生
 * Date: 2024-03-10
 * Time: 16:00
 */
@Data
public class Result {
    private int code;//200 -成功 -1 -失败 -2 -未登录
    private String errMsg;
    private Object data;

    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(Constant.SUCCESS_CODE);
        result.setErrMsg("登录成功");
        result.setData(data);
        return result;
    }

    public static Result fail(String errMsg, Object data) {
        Result result = new Result();
        result.setCode(Constant.FAIL_CODE);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }
    public static Result fail(String errMsg) {
        Result result = new Result();
        result.setCode(Constant.FAIL_CODE);
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }

    public static Result unLogin(String errMsg){
        Result result = new Result();
        result.setCode(Constant.UNLOGIN_CODE);
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }

    public static Result unLogin(String errMsg,Object data) {
        Result result = new Result();
        result.setCode(Constant.UNLOGIN_CODE);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }
}
